home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-16 | 23.0 KB | 826 lines | [TEXT/MPS ] |
- /*
- File: drag.c
-
- Copyright: © 1997-1998 by Apple Computer, Inc., all rights reserved.
-
- */
-
- //
- // You may incorporate this sample code into your applications
- // without restriction. This sample code has been provided "AS
- // IS" and the responsibility for its operation is 100% yours.
- // You are not permitted to redistribute the source as "Apple
- // sample code" after having made changes. If you're going to
- // re-distribute the source, we require that you make it clear
- // in the source that the code was descended from Apple sample
- // code, but that you've made changes.
- //
-
- #pragma segment DocSeg
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef Common_Defs
- #include "Common.h"
- #endif
-
- static long caretTime;
- static short caretOffset, caretShow, lastOffset, insertPosition, canAcceptItems;
- static short cursorInContent;
-
- #define gCaretTime ((short)*((long*)0x02F4)) // provides access to TextEdit's caretTime.
-
- short HitTest(Point theLoc, Document** theDoc);
- void DrawCaret(short offset, TEHandle theTE);
- char GetCharAtOffset(short offset, TEHandle theTE);
- Boolean WhiteSpace(char theChar);
- Boolean WhiteSpaceAtOffset(short offset, TEHandle theTE);
- void InsertTextAtOffset(short offset, char* theBuf, long size, StScrpHandle theStyl, TEHandle theTE);
- short GetSelectionSize(Document* theDocument);
- Ptr GetSelectedTextPtr(Document* theDocument);
-
- pascal OSErr MySendDataProc(FlavorType theType, void* refCon, ItemReference theItem, DragReference theDrag);
- pascal OSErr MyDrawingProc(DragRegionMessage message, RgnHandle showRgn, Point showOrigin, RgnHandle hideRgn, Point hideOrigin, void* dragDrawingRefCon, DragReference theDragRef);
- pascal OSErr MyReceiveDropHandler(WindowPtr theWindow, unsigned long handlerRefCon, DragReference theDrag);
- pascal OSErr MyTrackingHandler(short message, WindowPtr theWindow, void* handlerRefCon, DragReference theDrag);
-
- Boolean DropLocationIsFinderTrash(AEDesc* dropLocation);
-
- extern DragSendDataUPP sendHandler;
-
-
- // *****************************************************************************
- // *
- // * MyDrawingProc()
- // *
- // *****************************************************************************
- pascal OSErr MyDrawingProc(DragRegionMessage message, RgnHandle showRgn, Point /*showOrigin*/, RgnHandle hideRgn, Point /*hideOrigin*/, void* /*dragDrawingRefCon*/, DragReference /*theDragRef*/)
- {
- OSErr result = paramErr;
- RgnHandle tempRgn;
-
- switch(message)
- {
- case kDragRegionBegin:
- result = noErr;
- break;
-
- case kDragRegionDraw:
- XorRgn(showRgn,hideRgn,tempRgn = NewRgn());
- InvertRgn(tempRgn);
- DisposeRgn(tempRgn);
- result = noErr;
- break;
-
- case kDragRegionHide:
- InvertRgn(hideRgn);
- result = noErr;
- break;
- }
- return result;
- }
-
-
- // *****************************************************************************
- // *
- // * HitTest()
- // *
- // * Given a point in global coordinates, HitTest returns a pointer to a
- // * document structure if the point is inside a document window on the screen.
- // * If the point is not inside a document window, HitTest return NULL in
- // * theDoc. If the point is in a doument window and also in the viewRect of
- // * the document's TextEdit field, HitTest also returns the offset into
- // * the text that corresponds to that point. If the point is not in the text,
- // * HitTest returns -1.
- // *
- // *****************************************************************************
- short HitTest(Point theLoc, Document** theDoc)
- {
- WindowPtr theWindow;
- short offset;
-
- *theDoc = 0L;
- offset = -1;
-
- if (FindWindow(theLoc,&theWindow) == inContent)
- {
- if (*theDoc = IsDocumentWindow(theWindow))
- {
- SetPort(theWindow);
- GlobalToLocal(&theLoc);
-
- if ((PtInRect(theLoc, &(**((**theDoc).theTE)).viewRect)) &&
- (PtInRect(theLoc, &(**((**theDoc).theTE)).destRect)))
- {
- offset = TEGetOffset(theLoc,(**theDoc).theTE);
-
- if ((TEIsFrontOfLine(offset,(**theDoc).theTE)) && (offset) &&
- ((*((**((**theDoc).theTE)).hText))[offset - 1] != 0x0D) &&
- (TEGetPoint(offset - 1,(**theDoc).theTE).h < theLoc.h))
- {
- offset--;
- }
- }
- }
- }
- return offset;
- }
-
-
- // *****************************************************************************
- // *
- // * DrawCaret()
- // *
- // * Draws a caret in a TextEdit field at the given offset. DrawCaret
- // * expects the port to be set to the port that the TextEdit field is in.
- // * DrawCaret inverts the image of the caret onto the screen.
- // *
- // *****************************************************************************
- void DrawCaret(short offset, TEHandle theTE)
- {
- Point theLoc;
- short theLine, lineHeight;
-
- // get the coordinates and the line of the offset to draw the caret
- theLoc = TEGetPoint(offset,theTE);
- theLine = TEGetLine(offset,theTE);
-
- // For some reason, TextEdit dosen't return the proper coordinates
- // of the last offset in the field if the last character in the record
- // is a carriage return. TEGetPoint returns a point that is one line
- // higher than expected. The following code fixes this problem.
- if ((offset == (**theTE).teLength) && (*((**theTE).hText))[(**theTE).teLength - 1] == 0x0D)
- theLoc.v += TEGetHeight(theLine,theLine,theTE);
-
- PenMode(patXor); // invert the caret when drawing
- lineHeight = TEGetHeight(theLine,theLine,theTE); // get the height of the line that the offset points to
-
- MoveTo(theLoc.h - 1,theLoc.v - 1);
- Line(0,1 - lineHeight); // draw the appropriate caret image
-
- PenNormal();
- }
-
-
- // *****************************************************************************
- // *
- // * GetCharAtOffset()
- // *
- // *****************************************************************************
- char GetCharAtOffset(short offset, TEHandle theTE)
- {
- if (offset < 0)
- return(0x0D);
- return(((char *) *((**theTE).hText))[offset]);
- }
-
-
- // *****************************************************************************
- // *
- // * WhiteSpace()
- // *
- // *****************************************************************************
- Boolean WhiteSpace(char theChar)
- {
- return((theChar == ' ') || (theChar == 0x0D));
- }
-
-
- // *****************************************************************************
- // *
- // * WhiteSpaceAtOffset()
- // *
- // *****************************************************************************
- Boolean WhiteSpaceAtOffset(short offset, TEHandle theTE)
- {
- char theChar;
-
- if ((offset < 0) || (offset > (**theTE).teLength - 1))
- return(true);
-
- theChar = ((char *) *((**theTE).hText))[offset];
- return((theChar == ' ') || (theChar == 0x0D));
- }
-
-
- // *****************************************************************************
- // *
- // * InsertTextAtOffset()
- // *
- // *****************************************************************************
- void InsertTextAtOffset(short offset, char* theBuf, long size, StScrpHandle theStyl, TEHandle theTE)
- {
- if (size == 0)
- return;
-
- // If inserting at the end of a word and the selection does not begin with
- // a space, insert a space before the insertion.
- if (!WhiteSpaceAtOffset(offset - 1,theTE) && WhiteSpaceAtOffset(offset,theTE) && !WhiteSpace(theBuf[0]))
- {
- TESetSelect(offset,offset,theTE);
- TEKey(' ',theTE);
- offset++;
- }
-
- // If inserting at the beginning of a word and the selection does not end
- // with a space, insert a space after the insertion.
- if (WhiteSpaceAtOffset(offset - 1, theTE) && !WhiteSpaceAtOffset(offset, theTE) && !WhiteSpace(theBuf[size - 1]))
- {
- TESetSelect(offset, offset,theTE);
- TEKey(' ',theTE);
- }
-
- TESetSelect(offset,offset,theTE);
- TEStyleInsert(theBuf,size,theStyl,theTE);
- TESetSelect(offset,offset + size,theTE);
- }
-
-
- // *****************************************************************************
- // *
- // * GetSelectionSize()
- // *
- // *****************************************************************************
- short GetSelectionSize(Document* theDocument)
- {
- return((**(theDocument->theTE)).selEnd - (**(theDocument->theTE)).selStart);
- }
-
-
- // *****************************************************************************
- // *
- // * GetSelectedTextPtr()
- // *
- // *****************************************************************************
- Ptr GetSelectedTextPtr(Document* theDocument)
- {
- return((*(**(theDocument->theTE)).hText) + (**(theDocument->theTE)).selStart);
- }
-
-
- // *****************************************************************************
- // *
- // * MySendDataProc()
- // *
- // * Will provide 'styl' data for the drag when requested.
- // *
- // *****************************************************************************
- pascal OSErr MySendDataProc(FlavorType theType, void* refCon, ItemReference theItem, DragReference theDrag)
- {
- Document* theDocument = (Document*)refCon;
- StScrpHandle theStyl;
-
- if (theType == 'styl')
- {
- theStyl = TEGetStyleScrapHandle(theDocument->theTE);
-
- // Call SetDragItemFlavorData to provide the requested data.
- HLock((Handle) theStyl);
- SetDragItemFlavorData(theDrag,theItem,'styl',(Ptr)*theStyl,GetHandleSize((Handle)theStyl),0L);
- HUnlock((Handle)theStyl);
- DisposeHandle((Handle)theStyl);
- }
- else
- return badDragFlavorErr;
-
- return noErr;
- }
-
-
- // *****************************************************************************
- // *
- // * MyReceiveDropHandler()
- // *
- // *****************************************************************************
- pascal OSErr MyReceiveDropHandler(WindowPtr theWindow, unsigned long handlerRefCon, DragReference theDrag)
- {
- OSErr result;
- TEHandle tempTE;
- Rect theRect, srcRect;
- unsigned short items, index;
- ItemReference theItem;
- DragAttributes attributes;
- Ptr textData;
- StScrpHandle stylHandle;
- Size textSize, stylSize;
- short offset, selStart, selEnd, mouseDownModifiers, mouseUpModifiers, moveText;
- Document* theDocument = (Document*)handlerRefCon;
- Point thePoint;
-
- if ((!canAcceptItems) || (insertPosition == -1))
- return(dragNotAcceptedErr);
-
- SetPort(theWindow);
-
- GetDragAttributes(theDrag, &attributes);
- GetDragModifiers(theDrag, 0L, &mouseDownModifiers, &mouseUpModifiers);
-
- moveText = (attributes & kDragInsideSenderWindow) &&
- (!((mouseDownModifiers & optionKey) | (mouseUpModifiers & optionKey)));
-
- // Loop through all of the drag items contained in this drag and collect the text
- // into the tempTE record.
-
- SetRect(&theRect,0,0,0,0);
- tempTE = TEStyleNew(&theRect,&theRect);
-
- CountDragItems(theDrag, &items);
-
- for (index = 1; index <= items; index++)
- {
- GetDragItemReferenceNumber(theDrag, index, &theItem);
-
- // get the flags for a 'TEXT' flavor. If this returns noErr,
- // then we know that a 'TEXT' flavor exists in the item.
-
- result = GetFlavorDataSize(theDrag, theItem,'TEXT',&textSize);
-
- if (result == noErr)
- {
- textData = NewPtr(textSize);
- if (textData == 0L)
- {
- TEDispose(tempTE);
- return(memFullErr);
- }
-
- GetFlavorData(theDrag,theItem,'TEXT',textData,&textSize,0L);
-
- // check for optional styl data for the TEXT.
-
- stylHandle = 0L;
- result = GetFlavorDataSize(theDrag,theItem,'styl',&stylSize);
- if (result == noErr)
- {
- stylHandle = (StScrpHandle)NewHandle(stylSize);
- if (stylHandle == 0L)
- {
- TEDispose(tempTE);
- DisposePtr(textData);
- return(memFullErr);
- }
-
- HLock((Handle)stylHandle);
- GetFlavorData(theDrag,theItem,'styl',*stylHandle,&stylSize,0L);
- HUnlock((Handle)stylHandle);
- }
-
- // insert this drag item's text into the tempTE
-
- TESetSelect(32767,32767,tempTE);
- TEStyleInsert(textData,textSize,stylHandle,tempTE);
-
- DisposePtr(textData);
- if (stylHandle)
- DisposeHandle((Handle) stylHandle);
- }
- }
-
- // pull the TEXT and styl data out of the tempTE handle.
-
- textData = NewPtr(textSize = (**tempTE).teLength);
- if (textData == 0L)
- {
- TEDispose(tempTE);
- return(memFullErr);
- }
- BlockMove(*(**tempTE).hText,textData,textSize);
-
- TESetSelect(0,32767,tempTE);
- stylHandle = TEGetStyleScrapHandle(tempTE);
-
- TEDispose(tempTE);
-
- // if we actually received text, insert it into the destination
-
- if (textSize != 0)
- {
- // if the caret or highlighting is on the screen, remove it/them
-
- offset = caretOffset;
-
- if (caretOffset != -1)
- {
- DrawCaret(caretOffset,theDocument->theTE);
- caretOffset = -1;
- }
-
- if (attributes & kDragHasLeftSenderWindow)
- HideDragHilite(theDrag);
-
- // If the drag occurred completely within the same window and the window is not
- // frontmost, bring the window forward and update its contents before completing
- // the drag.
-
- if ((attributes & kDragInsideSenderWindow) && (theDocument->theWindow != FrontWindow()))
- {
- SelectWindow(theDocument->theWindow);
- UpdateWindow(theDocument);
- TEActivate(theDocument->theTE);
- }
-
- // if the window is not active, must activate TE before inserting
- // text or the background hilite will not update correctly.
-
- if (!((WindowPeek) theDocument->theWindow)->hilited)
- if (!IsWindowHilited(theDocument->theWindow))
- TEActivate(theDocument->theTE);
-
- // if this window is also the sender, delete source selection if no option key.
- if (moveText)
- {
- selStart = (**(theDocument->theTE)).selStart;
- selEnd = (**(theDocument->theTE)).selEnd;
- if ( WhiteSpaceAtOffset(selStart - 1, theDocument->theTE) &&
- !WhiteSpaceAtOffset(selStart, theDocument->theTE) &&
- !WhiteSpaceAtOffset(selEnd - 1, theDocument->theTE) &&
- WhiteSpaceAtOffset(selEnd, theDocument->theTE))
- {
- if (GetCharAtOffset(selEnd, theDocument->theTE) == ' ')
- (**(theDocument->theTE)).selEnd++;
- }
- if (insertPosition > selStart)
- {
- insertPosition -= ((**(theDocument->theTE)).selEnd -
- (**(theDocument->theTE)).selStart);
- }
- srcRect = (**theDocument->hiliteRgn).rgnBBox;
- TEDelete(theDocument->theTE);
- }
-
- InsertTextAtOffset(insertPosition,textData,textSize,stylHandle,theDocument->theTE);
-
- TEGetHiliteRgn(theDocument->hiliteRgn, theDocument->theTE);
-
- // If the text is moving (not copying) within the same window, provide a ZoomRects
- // from the source to the destination before revealing the reflowed text.
-
- if (moveText)
- {
- theRect = (**theDocument->hiliteRgn).rgnBBox;
- thePoint.h = thePoint.v = 0;
-
- SetPort(theWindow);
-
- LocalToGlobal(&thePoint);
- OffsetRect(&srcRect,thePoint.h,thePoint.v);
- OffsetRect(&theRect,thePoint.h,thePoint.v);
- ZoomRects(&srcRect,&theRect,12,kZoomDecelerate);
- }
- theDocument->dirty = true;
- }
-
- DisposePtr(textData);
-
- if (stylHandle)
- DisposeHandle((Handle)stylHandle);
-
- // undo the TEActivate, if needed
- if (!IsWindowHilited(theDocument->theWindow))
- if (!((WindowPeek) theDocument->theWindow)->hilited)
- TEDeactivate(theDocument->theTE);
-
- (**(theDocument->theTE)).inPort = (GrafPtr)theDocument->theWindow;
-
- return noErr;
- }
-
-
- // *****************************************************************************
- // *
- // * MyTrackingHandler()
- // *
- // * This is the drag tracking handler for windows in the application.
- // *
- // *****************************************************************************
- pascal OSErr MyTrackingHandler(short message, WindowPtr /*theWindow*/, void* handlerRefCon, DragReference theDrag)
- {
- short result, offset;
- long theTime = TickCount();
- unsigned short count, index;
- unsigned long flavorFlags, attributes;
- ItemReference theItem;
- RgnHandle theRgn;
- Document* theDocument = (Document*)handlerRefCon;
- Document* hitDoc;
- Point theMouse, localMouse;
-
- if ((message != kDragTrackingEnterHandler) && (!canAcceptItems))
- return(noErr);
-
- GetDragAttributes(theDrag, &attributes);
-
- switch (message)
- {
- case kDragTrackingEnterHandler:
-
- // We get called with this message the first time that a drag enters ANY
- // window in our application. Check to see if all of the drag items contain
- // TEXT. We only accept a drag if all of the items in the drag can be accepted.
-
- canAcceptItems = true;
-
- CountDragItems(theDrag, &count);
-
- for (index = 1; index <= count; index++)
- {
- GetDragItemReferenceNumber(theDrag,index,&theItem);
-
- result = GetFlavorFlags(theDrag, theItem,'TEXT',&flavorFlags);
-
- if (result != noErr)
- {
- canAcceptItems = false;
- break;
- }
- }
- break;
-
- case kDragTrackingEnterWindow:
-
- // We receive an EnterWindow message each time a drag enters one of our
- // application's windows. We initialize our global variables for tracking
- // the drag through the window.
-
- caretTime = theTime;
- caretOffset = lastOffset = -1;
- caretShow = true;
-
- cursorInContent = false;
-
- break;
-
- case kDragTrackingInWindow:
-
- // We receive InWindow messages as long as the mouse is in one of our windows
- // during a drag. We draw the window highlighting and blink the insertion caret
- // when we get these messages.
-
- GetDragMouse(theDrag,&theMouse,0L);
- localMouse = theMouse;
- GlobalToLocal(&localMouse);
-
- // Show or hide the window highlighting when the mouse enters or leaves the
- // TextEdit field in our window (we don't want to show the highlighting when
- // the mouse is over the window title bar or over the scroll bars).
-
- if (attributes & kDragHasLeftSenderWindow)
- {
- if (PtInRect(localMouse, &(**(theDocument->theTE)).viewRect))
- {
- if (!cursorInContent)
- {
- RectRgn(theRgn = NewRgn(),&(**(theDocument->theTE)).viewRect);
- ShowDragHilite(theDrag,theRgn,true);
- DisposeRgn(theRgn);
- }
- cursorInContent = true;
- }
- else
- {
- if (cursorInContent)
- HideDragHilite(theDrag);
- cursorInContent = false;
- }
- }
-
- offset = HitTest(theMouse, &hitDoc);
-
- // If this application is the sender, do not allow tracking through
- // the selection in the window that sourced the drag.
-
- if (attributes & kDragInsideSenderWindow)
- {
- if ((offset >= (**(theDocument->theTE)).selStart) &&
- (offset <= (**(theDocument->theTE)).selEnd))
- offset = -1;
- }
-
- if (hitDoc == theDocument)
- {
- insertPosition = offset;
-
- // Reset flashing counter if the offset has moved. This makes the
- // caret blink only after the caret has stopped moving long enough.
-
- if (offset != lastOffset)
- {
- caretTime = theTime;
- caretShow = true;
- }
- lastOffset = offset;
-
- // flash caret
-
- if (theTime - caretTime > gCaretTime)
- {
- caretShow = !caretShow;
- caretTime = theTime;
- }
- if (!caretShow)
- offset = -1;
-
- // if caret offset has changed, move caret on screen
-
- if (offset != caretOffset)
- {
- if (caretOffset != -1)
- {
- DrawCaret(caretOffset,theDocument->theTE);
- }
- if (offset != -1)
- {
- DrawCaret(offset,theDocument->theTE);
- }
- }
-
- caretOffset = offset;
- }
- else
- {
- lastOffset = offset;
- insertPosition = -1;
- }
- break;
-
- case kDragTrackingLeaveWindow:
-
- // if the caret is on the screen, remove it.
-
- if (caretOffset != -1)
- {
- DrawCaret(caretOffset,theDocument->theTE);
- caretOffset = -1;
- }
-
- // remove window highlighting, if showing.
-
- if ((cursorInContent) && (attributes & kDragHasLeftSenderWindow))
- HideDragHilite(theDrag);
- break;
-
- case kDragTrackingLeaveHandler:
- break;
-
- }
- return noErr;
- }
-
-
- // *****************************************************************************
- // *
- // * DropLocationIsFinderTrash()
- // *
- // * Returns true if the given dropLocation AEDesc is a descriptor of the Finder's Trash.
- // *
- // *****************************************************************************
- Boolean DropLocationIsFinderTrash(AEDesc* dropLocation)
- {
- OSErr result;
- AEDesc dropSpec;
- FSSpec* theSpec;
- CInfoPBRec thePB;
- short trashVRefNum;
- long trashDirID;
-
- // Coerce the dropLocation descriptor to an FSSpec. If there's no dropLocation or
- // it can't be coerced into an FSSpec, then it couldn't have been the Trash.
-
- if ((dropLocation->descriptorType != typeNull) &&
- (AECoerceDesc(dropLocation, typeFSS, &dropSpec) == noErr))
- {
- HLock(dropSpec.dataHandle);
- theSpec = (FSSpec*)*dropSpec.dataHandle;
-
- // get the directory ID of the given dropLocation object
- thePB.dirInfo.ioCompletion = 0L;
- thePB.dirInfo.ioNamePtr = (StringPtr) &theSpec->name;
- thePB.dirInfo.ioVRefNum = theSpec->vRefNum;
- thePB.dirInfo.ioFDirIndex = 0;
- thePB.dirInfo.ioDrDirID = theSpec->parID;
-
- result = PBGetCatInfoSync(&thePB);
-
- HUnlock(dropSpec.dataHandle);
- AEDisposeDesc(&dropSpec);
-
- if (result != noErr)
- return(false);
-
- // if the result is not a directory, it must not be the Trash.
- if (!(thePB.dirInfo.ioFlAttrib & (1 << 4)))
- return false;
-
- // get information about the Trash folder
- FindFolder(theSpec->vRefNum,kTrashFolderType,kCreateFolder,&trashVRefNum,&trashDirID);
-
- // if the directory ID of the dropLocation object is the same as the directory ID
- // returned by FindFolder, then the drop must have occurred into the Trash.
-
- if (thePB.dirInfo.ioDrDirID == trashDirID)
- return true;
- }
- return false;
- }
-
-
- // *****************************************************************************
- // *
- // * DragText()
- // *
- // *****************************************************************************
- short DragText(Document* theDocument, EventRecord* theEvent, RgnHandle hiliteRgn)
- {
- OSErr theErr = noErr;
- short result;
- RgnHandle dragRegion, tempRgn;
- Point theLoc;
- DragReference theDrag;
- StScrpHandle theStyl;
- AEDesc dropLocation;
- DragAttributes attributes;
- short mouseDownModifiers, mouseUpModifiers, copyText;
-
- // copy the hilite region into dragRegion and offset it into global coordinates.
- CopyRgn(hiliteRgn,dragRegion = NewRgn());
- SetPt(&theLoc,0,0);
- LocalToGlobal(&theLoc);
- OffsetRgn(dragRegion,theLoc.h,theLoc.v);
-
- if (!WaitMouseMoved(theEvent->where))
- return false;
-
- NewDrag(&theDrag);
-
- AddDragItemFlavor(theDrag,1,'TEXT',GetSelectedTextPtr(theDocument),GetSelectionSize(theDocument),0);
-
- theStyl = TEGetStyleScrapHandle(theDocument->theTE);
- HLock((Handle) theStyl);
- AddDragItemFlavor(theDrag,1,'styl',(Ptr)*theStyl,GetHandleSize((Handle)theStyl),0);
- HUnlock((Handle) theStyl);
- DisposeHandle((Handle)theStyl);
-
- sendHandler = NewDragSendDataProc(&MySendDataProc);
- theErr = SetDragSendProc(theDrag,sendHandler,(void*)theDocument);
-
- SetDragItemBounds(theDrag,1,&(**dragRegion).rgnBBox);
-
- // prepare the drag region
- tempRgn = NewRgn();
- CopyRgn(dragRegion,tempRgn);
- InsetRgn(tempRgn,1,1);
- DiffRgn(dragRegion,tempRgn,dragRegion);
- DisposeRgn(tempRgn);
-
- /*
- // use this if you want custom draw outlines..
- if (gCanDrag)
- {
- #if USESROUTINEDESCRIPTORS
- sendHandler = NewDragSendDataProc(&MyDrawingProc);
- theErr = SetDragDrawingProc(theDrag,drawHandler,0L);
- #else
- theErr = SetDragDrawingProc(theDrag,MyDrawingProc,0L);
- #endif
- }
- */
-
- result = TrackDrag(theDrag,theEvent,dragRegion);
-
- if (result != noErr && result != userCanceledErr)
- return true;
-
- // check to see if the drop occurred in the Finder's Trash. If the drop occurred
- // in the Finder's Trash and a copy operation wasn't specified, delete the source selection
-
- GetDragAttributes(theDrag,&attributes);
- if (!(attributes & kDragInsideSenderApplication))
- {
- GetDropLocation(theDrag,&dropLocation);
-
- GetDragModifiers(theDrag,0L,&mouseDownModifiers,&mouseUpModifiers);
- copyText = (mouseDownModifiers | mouseUpModifiers) & optionKey;
-
- if ((!copyText) && (DropLocationIsFinderTrash(&dropLocation)))
- {
- TEDelete(theDocument->theTE);
- theDocument->dirty = true;
- }
- AEDisposeDesc(&dropLocation);
- }
-
- DisposeDrag(theDrag);
- DisposeRgn(dragRegion);
-
- return true;
- }